﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace ETERNAL
{
    class AnimatedSprite
    {
        public Texture2D objectSprite;
        public Vector2 origin;

        protected Rectangle spriteRectangle;
        protected const int spriteWidth = 96;
        protected const int spriteHeight = 96;
        protected float angle = 0.0f;

        private int currentFrame;

        public void Load(ContentManager cM, string fileName)
        {
            objectSprite = cM.Load<Texture2D>(fileName);
        }
        public void DrawSprite(SpriteBatch spriteBatch, Vector2 pos)
        {
            if (currentFrame < 4)
            {
                currentFrame++;
            }
            else
                currentFrame = 0;
            spriteBatch.Draw(objectSprite, pos, spriteRectangle, Color.White, angle, origin, 1.0f, SpriteEffects.None, 1);
        }

        public void RunAnimation()
        {
            origin = new Vector2(spriteRectangle.Width / 2, spriteRectangle.Height / 2);
            spriteRectangle = new Rectangle(currentFrame * spriteWidth, 0, spriteWidth, spriteHeight);
        }

        public void RotateSprite(bool clockwise)
        {
            if (clockwise)
                angle += 0.1f;
            else
                angle -= 0.1f;
        }
    }
}
